package main.java.com.chegg.coursepicker;
import java.util.TreeMap;

import tml.vectorspace.TermWeighting.GlobalWeight;
 import tml.vectorspace.TermWeighting.LocalWeight;
import tml.vectorspace.operations.PassagesSimilarity;
 import tml.annotators.PennTreeAnnotator;
 import tml.corpus.SearchResultsCorpus;
 import tml.corpus.CorpusParameters.DimensionalityReduction;
 import tml.corpus.CorpusParameters.TermSelection;
import tml.storage.Repository;
 
public class PerformingOperationOnCorpus {
 
    public TreeMap findSimilarity() throws Exception {
         Repository repository = new Repository("C://opt//docs//repository");
 
        SearchResultsCorpus corpus = new SearchResultsCorpus("type:document");
         corpus.getParameters().setTermSelectionCriterion(TermSelection.DF);
         corpus.getParameters().setTermSelectionThreshold(0);
         corpus.getParameters().setDimensionalityReduction(DimensionalityReduction.NUM);
         corpus.getParameters().setDimensionalityReductionThreshold(50);
         corpus.getParameters().setTermWeightGlobal(GlobalWeight.Entropy);
         corpus.getParameters().setTermWeightLocal(LocalWeight.LOGTF);
         corpus.load(repository);
         
         System.out.println("Corpus loaded and Semantic space calculated");
         System.out.println("Total documents:" + corpus.getPassages().length);
 
        PassagesSimilarity distances = new PassagesSimilarity();
         distances.setCorpus(corpus);
         distances.start();
 
         String result = distances.getResultsCSVString();
         String resultarr[] = result.split("\n");
         TreeMap tmp = new TreeMap();
         for(int i=0;i<resultarr.length;i++){
        	 String subset[] = resultarr[i].toString().split(",");
        	 if(subset[0].equalsIgnoreCase("COURSE9") &&  !subset[0].equalsIgnoreCase(subset[1]) ){
        		
        		 tmp.put(subset[1], subset[2]);
        			 
        	 }
        	 if(subset[1].equalsIgnoreCase("COURSE9") &&  !subset[0].equalsIgnoreCase(subset[1]) ){
         		
        		 tmp.put(subset[0], subset[2]);
    		 }
        	 
         }
         
         System.out.println("tmp *********** \n"+tmp.entrySet().toString());
         return tmp;
         
     }
 }